/*
 * All Rights Reserved.
 *
 * 
 * Author : Madhur Raj
 */

#include <stdio.h>
#include <stdlib.h>


/* Static Data */
char filename[]="/project/madhur/CFun/sort/readfile.txt";

/* Forward decalarations */
extern int* getNode();


void readfile()
{
   FILE *fp;
   int len;
   int *data;

   fp = fopen(filename, "r");
   if (!fp)
   {
      printf("Failed to read file\n");
      return;
   }

   fseek(fp, 0L, SEEK_END); /* Move to the end of file */
   len = ftell(fp);         /* Get the length */
   rewind(fp);           /* Get back to start of file */

   while (ftell(fp) != len-1)
   {
      data = getNode();
      fscanf(fp, "%d", data);
   }

   return ;
}

void printTime(struct timeval *start, struct timeval *finish)
{
   if (finish->tv_usec < start->tv_usec)
   {
      printf("Time taken %ld sec %ld microsec\n",finish->tv_sec - start->tv_sec-1,
                                      1000000 + finish->tv_usec - start->tv_usec);
   }
   else
   {
      printf("Time taken %ld sec %ld microsec\n", finish->tv_sec - start->tv_sec,
                                            finish->tv_usec - start->tv_usec);
   }

}
